<script setup lang="ts">
// #ifdef MP
import { onAddToFavorites, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { wxCollect, wxShare } from '@/libs/share'

onShareAppMessage(wxShare(true))
onShareTimeline(wxShare(false))
onAddToFavorites(wxCollect())
// #endif

import { onMounted, onUnmounted } from 'vue'

import { clear, detail, update } from './data'
import { imagePath } from '@/libs/file-utils'
import { backToMain } from '@/libs/common';

const props = defineProps<{ id: string }>()

const img_bg = imagePath('community/group/qrcode/bg.jpg')
const card_qrcode = imagePath('community/group/qrcode/card-qrcode.png')
const icon_group_normal = imagePath('community/group/normal/icon-group.png')
const icon_group_advanced = imagePath('community/group/advanced/icon-group.png')

if (props.id) {
  onMounted(() => update(props.id))
  onUnmounted(clear)
} else backToMain()
</script>

<template>
  <PageWrapper
    name="community-group-qrcode"
    :pageStyle="{ backgroundImage: img_bg }"
  >
    <div
      v-if="detail"
      class="box"
    >
      <div class="desc">
        <div
          class="icon"
          :style="{ backgroundImage: detail.groupType === 1 ? icon_group_normal : icon_group_advanced }"
        ></div>
        <div class="info">
          <div class="name">{{ detail.groupName }}</div>
          <div>{{ detail.groupDesc }}</div>
        </div>
      </div>

      <div class="tip">{{ '长按保存图片\n识别二维码入群' }}</div>

      <div
        class="card"
        :style="{ backgroundImage: card_qrcode }"
      >
        <image
          class="inner"
          :src="detail.grCodeUrl"
          mode="aspectFit"
          show-menu-by-longpress
        />
      </div>
    </div>
  </PageWrapper>
</template>

<style lang="less" scoped>
.box {
  width: 686rpx;

  margin: 42rpx auto;

  box-sizing: border-box;
  padding: 48rpx;

  border-radius: 32rpx;
  background-color: #FAEFFE;
  box-shadow: 0 6rpx 25rpx 0 rgba(154, 73, 255, .6);

  .desc {
    width: 100%;

    display: flex;
    align-items: center;

    .icon {
      width: 100rpx;
      height: 100rpx;
    }

    .info {
      margin-left: 16rpx;
      // flex: 1;

      color: #51008A;
      font-size: 24rpx;
      line-height: 34rpx;

      .name {
        margin-bottom: 10rpx;
        font-size: 48rpx;
        line-height: 48rpx;
      }
    }
  }

  .tip {
    margin-top: 32rpx;

    color: #222;
    font-size: 32rpx;
    line-height: 48rpx;
    white-space: pre;
  }

  .card {
    position: relative;
    width: 562rpx;
    height: 562rpx;

    margin: 46rpx auto 64rpx;

    .inner {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);

      width: 416rpx;
      height: 416rpx;

      border-radius: 16rpx;
      background-color: #fff;
    }
  }
}
</style>